/**
 * 功能描述
 */
define(function (require, exports, module) {
    //引入视图基类
    var ELView = require("elview");

    //assets
    var template = require("./assets/tpl/preadjust_main.tpl");
    require("./assets/css/preadjust_main.css");

    //business

    //component
    var preAdjustSubnav = require("./component/preAdjustSubnav");
    var preAdjustForm = require("./component/preAdjustForm");
    var preAdjustGrid = require("./component/preAdjustGrid");
    var preAdjustAddFormComp = require("./component/preAdjustAddFormComp");
    var roomAddFormComp = require("./component/roomAddFormComp");
    var nonMemFormComp = require("../../nonmemsignup/src/component/reservegrid");
    var nonMemRoomGridComp = require("../../nonmemsignup/src/component/nonMemForm");
    var reserveRoomDetailGrid = require("./component/reserveRoomDetailGrid");
    //constant

    var handler = require("./handler/preAdjustEvents");
    var nonMemAdjustEvents = require("./handler/nonMemAdjustEvents");
    //handler

    //store
    var preAdjustSvc = require("./service/preAdjustSvc");
    var fetchProperties = require("./constant/fetchProperties");
    
    var App = ELView.extend({
        attrs: {
            template: template
        },
        events:{
			"change .J-form-addRoomForm-select-orgBuilding":function(e){
				var widget = this;
				handler.changeFormBuild(widget);
			},
			"change .J-form-addRoomForm-select-roomType":function(e){
				var widget = this;
				handler.changeFormRoom(widget);
			}
		},
        handler:handler,
        nonMemHandler: nonMemAdjustEvents,
        // 退团人员
        exitData:[],
        // 调整类型
        adjustTypes:[],
        // 所有人员
        signUpDatas:[],
        signUpRoomDatas:[],
        service:preAdjustSvc,
        // 预约散客团为true
        NonMember:false,
        initComponent: function (params, widget) {
        	preAdjustSubnav.initComponent(params, widget);
        	preAdjustForm.initComponent(params, widget);
        	preAdjustGrid.initComponent(params, widget);
        	preAdjustAddFormComp.initComponent(params, widget);
        	roomAddFormComp.initComponent(params, widget);
        	nonMemFormComp.initComponent(params, widget);
        	nonMemRoomGridComp.initComponent(params, widget);
        	reserveRoomDetailGrid.initComponent(params, widget);
        },
        afterInitComponent: function (params, widget) {
        	var subnav=widget.get("subnav");
        	var grid=widget.get("grid");
        	subnav.load("destination", {
                callback: function(data) {
                    subnav.setData("destination", data);
                    grid.refresh();
                }
            });
        },
        toGrid: function(){
        	this.exitData=[];
        	this.adjustTypes=[];
        	this.signUpDatas=[];
        	this.signUpRoomDatas=[];
        	this.NonMember = false;
        	this.show([".J-grid"]).hide([".J-adjustForm",".J-addForm",".J-tab",".J-editgrid",".J-form"]);
			this.get("subnav").hide(["return","save","cancel"]).show(["destination","dateRange"]);
        },
        toForm: function(data){
        	this.set("tempGridRowData",data);
        	if(this.NonMember){
        		this.show([".J-editgrid",".J-form"]);
        	}else{
        		this.show([".J-adjustForm",".J-tab"])
        	}
        	this.hide([".J-grid",".J-addForm"]);
			this.get("subnav").show(["return","save","cancel"]).hide(["destination","dateRange"]);
        },
        toAddForm:function(){
        	this.show([".J-addForm"]).hide([".J-grid",".J-adjustForm",".J-tab"]);
			this.get("subnav").hide(["return","save","cancel","destination","dateRange"]);
			this.get("addForm").reset();
        },
        toAddRoomForm:function(){
        	this.show([".J-addRoomForm"]).hide([".J-grid",".J-adjustForm",".J-tab"]);
			this.get("subnav").hide(["return","save","cancel","destination","dateRange"]);
			this.get("addRoomForm").reset();
        },
        toRoomForm: function(data){
        	this.set("tempGridRowData",data);
        	if(this.NonMember){
        		this.show([".J-editgrid",".J-form"]);
        	}else{
        		this.show([".J-adjustForm",".J-tab"])
        	}
        	this.hide([".J-grid",".J-addRoomForm"]);
			this.get("subnav").show(["return","save","cancel"]).hide(["destination","dateRange"]);
        },
        refreshRoomGrid:function(widget){
			widget.service.queryChargeStatus({
				"pkPlanItemGroup":widget.get("data").planItemGroup.pkPlanItemGroup,
				fetchProperties:fetchProperties.chargestatus
			},function(data){
				widget.get("roomGrid").setData(data.length>0?data[0].groupReserve.roomRegisters:[]);
			})
		},
		showRoomBtn:function(data){
			if(data&&data.groupStatus&&data.groupStatus.key=="Reserve"){
				$("#roomAdd").show();
				$(".J-grid-roomGrid-del").show();
			}else{
				$("#roomAdd").hide();
				$(".J-grid-roomGrid-del").hide();
			}
		}
    });

    module.exports = App;
});
